package com.dly.blog.event;

import com.dly.blog.domain.GptSessionContent;
import com.dly.blog.service.GptSessionContentService;
import lombok.AllArgsConstructor;
import lombok.NonNull;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Async
@AllArgsConstructor
@Component
public class GptContentEventListener implements ApplicationListener<GptContentEvent> {

    private final GptSessionContentService gptSessionContentService;

    @Override
    public void onApplicationEvent(@NonNull GptContentEvent event) {
        if(event.getSource() instanceof GptSessionContent gptSessionContent){
            gptSessionContentService.save(gptSessionContent);
        }
    }

}
